<template>
  <div class="contents">
<div class="Framecont">
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" label-color="white" class="demo-ruleForm">
  
    <el-form-item label="账号" prop="name" >
    <el-input v-model.number="ruleForm.name" ref="ph"></el-input>
  </el-form-item>
  
  <el-form-item label="密码" prop="pass" ref="ps">
    <el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
  </el-form-item>
  <!-- <el-form-item label="确认密码" prop="checkPass">
    <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
  </el-form-item> -->

  <el-form-item>
    <el-button id="but1" type="primary" @click="submitForm('ruleForm')">登录</el-button>
    <el-button id="but2" @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
</el-form>
</div>

  </div>
</template>

<script>
 export default {
    data() {
      var checkName = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('账号不能为空'));
        }
        callback()
      
      };
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        } else {
          if (this.ruleForm.checkPass !== '') {
            this.$refs.ruleForm.validateField('checkPass');
          }
          callback();
        }
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.ruleForm.pass) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      return {
        // 账号和密码
         phones:"",
         passwords:"",

        ruleForm: {
          pass: 'admin',
          name:'admin' 
        },
        rules: {
          pass: [
            { validator: validatePass, trigger: 'blur' }
          ],
          checkPass: [
            { validator: validatePass2, trigger: 'blur' }
          ],
          name: [
      
            { validator: checkName, trigger: 'blur' }
          ]
        }
      };
    },

 
   
    methods: {
     


      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
           let name =  this.ruleForm.name
           let password = this.ruleForm.pass
           console.log(name);
          if (valid) {
          this.$http.post('/login/'
        
          ,{
           name,
          password
        //  name:"admin",
        //  password:"admin"
          }).then((res)=>{
               console.log(res);
               if(res.code == 0)
               {
               this.$router.push({
                 name: "Audit",}) 
         localStorage.setItem('token_z',res.info.token)
         this.$notify({
          title: '成功',
          message: '登录成功！',
          type: 'success'
        });;}
         else{this.$notify.error({
          title: '提交失败',
          message: '账号不存在，或密码填写错误！',
          duration:1000
        });}
         })

          } else {
            console.log('error submit!!');
              this.$notify.error({
          title: '错误',
          message: '提交失败，信息填写错误！',
          duration:700
        });
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
         this.$notify.info({
          title: '消息',
          message: '重置成功！',
          duration:700
        });
      }
    }
  }
</script>

<style >
*{margin: 0px;padding: 0px;}
.el-form-item__label{color:white}
.contents{width: 100%;height: 100%;background-image: linear-gradient(-180deg, #1a1454 0%, #0e81a5 100%);
background-size: 100%;}
.Framecont{width:35%;margin: auto;background:rgba(0, 0, 0, 0.5);
padding:65px 50px 5px 0px;border-radius:20px;position: relative;top:180px;}
#but1{margin-right:20px;}
#but2{margin-left:20px ;}
</style>